#ifndef _TEXTUREMANAGER_H_
#define _TEXTUREMANAGER_H_

#include <d3d9.h>

#define MAX_TEXTURES 512

struct TextureItem
{
	char filename[32];
	bool loaded;
	IDirect3DTexture9 *texture;
	int  textureID;
};

class TextureManager
{
	static TextureManager Instance;

	TextureManager(void);
	TextureManager(const TextureManager& );
	~TextureManager(void);
	TextureManager& operator=(const TextureManager& );

	TextureItem textureItems[MAX_TEXTURES];

public:
	static TextureManager* GetInstance(void) { return &Instance; }

	bool Init(IDirect3DDevice9 *device);
	void Shutdown();

	void ReleaseAll();

	int LoadTexture(const char *filename);
	int LoadTextureInMemory(const char *filename, void* pSrcData, unsigned int SrcDataSize );

	IDirect3DTexture9 *GetTextureByID(int id);
	void ReleaseTextureByID(int id);

	int Count() { return currentCount; }
private:
	IDirect3DDevice9 *device;
	int currentCount;
	int nextID;

	int DoesTextureExist(const char *filename);
	int FindFirstEmpty();
};

#endif _TEXTUREMANAGER_H_